package com.javafactroy.kunlong.framework.elasticsearch;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class EsClient {

    @Value("${spring.es.host:http://huawei.akunlong.top:9200}")
    private String[] urls;

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        // 创建多个HttpHost
        HttpHost[] httpHosts = Arrays.stream(urls).map(HttpHost::create).toArray(HttpHost[]::new);

        return new RestHighLevelClient(RestClient.builder(httpHosts));
    }
}